package com.zy.openchat.core.model.message;

import android.os.Parcel;
import android.os.Parcelable;

import java.util.List;

public class ChatPermissions implements Parcelable {
    public boolean can_send_messages;
    public boolean can_send_media_messages;
    public boolean can_send_polls;
    public boolean can_send_other_messages;
    public boolean can_add_web_page_previews;
    public boolean can_change_info;
    public boolean can_invite_users;
    public boolean can_pin_messages;

    //禁止私聊
    public boolean banWhisper;
    //禁止发送网页链接
    public boolean banSendWebLink;
    //禁止发送二维码
    public boolean banSendQRcode;
    //禁止发送关键字
    public boolean banSendKeyword;
    //发送关键字会被踢出群聊
    public boolean kickWhoSendKeyword;
    //发送关键字会被踢出群聊
    public boolean showKickMessage;
    public List<String> keywords;


    @Override
    public int describeContents() {
        return 0;
    }

    @Override
    public void writeToParcel(Parcel dest, int flags) {
        dest.writeByte(this.can_send_messages ? (byte) 1 : (byte) 0);
        dest.writeByte(this.can_send_media_messages ? (byte) 1 : (byte) 0);
        dest.writeByte(this.can_send_polls ? (byte) 1 : (byte) 0);
        dest.writeByte(this.can_send_other_messages ? (byte) 1 : (byte) 0);
        dest.writeByte(this.can_add_web_page_previews ? (byte) 1 : (byte) 0);
        dest.writeByte(this.can_change_info ? (byte) 1 : (byte) 0);
        dest.writeByte(this.can_invite_users ? (byte) 1 : (byte) 0);
        dest.writeByte(this.can_pin_messages ? (byte) 1 : (byte) 0);
        dest.writeByte(this.banWhisper ? (byte) 1 : (byte) 0);
        dest.writeByte(this.banSendWebLink ? (byte) 1 : (byte) 0);
        dest.writeByte(this.banSendQRcode ? (byte) 1 : (byte) 0);
        dest.writeByte(this.banSendKeyword ? (byte) 1 : (byte) 0);
        dest.writeByte(this.kickWhoSendKeyword ? (byte) 1 : (byte) 0);
        dest.writeByte(this.showKickMessage ? (byte) 1 : (byte) 0);
        dest.writeStringList(this.keywords);
    }

    public void readFromParcel(Parcel source) {
        this.can_send_messages = source.readByte() != 0;
        this.can_send_media_messages = source.readByte() != 0;
        this.can_send_polls = source.readByte() != 0;
        this.can_send_other_messages = source.readByte() != 0;
        this.can_add_web_page_previews = source.readByte() != 0;
        this.can_change_info = source.readByte() != 0;
        this.can_invite_users = source.readByte() != 0;
        this.can_pin_messages = source.readByte() != 0;
        this.banWhisper = source.readByte() != 0;
        this.banSendWebLink = source.readByte() != 0;
        this.banSendQRcode = source.readByte() != 0;
        this.banSendKeyword = source.readByte() != 0;
        this.kickWhoSendKeyword = source.readByte() != 0;
        this.showKickMessage = source.readByte() != 0;
        this.keywords = source.createStringArrayList();
    }

    public ChatPermissions() {
    }

    protected ChatPermissions(Parcel in) {
        this.can_send_messages = in.readByte() != 0;
        this.can_send_media_messages = in.readByte() != 0;
        this.can_send_polls = in.readByte() != 0;
        this.can_send_other_messages = in.readByte() != 0;
        this.can_add_web_page_previews = in.readByte() != 0;
        this.can_change_info = in.readByte() != 0;
        this.can_invite_users = in.readByte() != 0;
        this.can_pin_messages = in.readByte() != 0;
        this.banWhisper = in.readByte() != 0;
        this.banSendWebLink = in.readByte() != 0;
        this.banSendQRcode = in.readByte() != 0;
        this.banSendKeyword = in.readByte() != 0;
        this.kickWhoSendKeyword = in.readByte() != 0;
        this.showKickMessage = in.readByte() != 0;
        this.keywords = in.createStringArrayList();
    }

    public static final Creator<ChatPermissions> CREATOR = new Creator<ChatPermissions>() {
        @Override
        public ChatPermissions createFromParcel(Parcel source) {
            return new ChatPermissions(source);
        }

        @Override
        public ChatPermissions[] newArray(int size) {
            return new ChatPermissions[size];
        }
    };
}
